package com.tarena.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.tarena.dao.DeptDao;
import com.tarena.domain.Dept;

public class SelectAllEmp implements Servlet{

	public void destroy() {
		
	}

	public ServletConfig getServletConfig() {
		return null;
	}

	public String getServletInfo() {
		return null;
	}

	public void init(ServletConfig arg0) throws ServletException {
		
	}

	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		//设置响应协议头的contentType信息,要放在输出流语句之上，
		//保证流对象可以用适当的编码输出
		response.setContentType("text/html;charset=utf-8");
		
		//Map map = request.getParameterMap();
		//String[] email = request.getParameterValues("emial");
 		List<Dept> list = new DeptDao().getAllDept();	
		
		PrintWriter out = response.getWriter();
		//得到该表中的全部员工对象
		
		out.println("<html>");
		out.println("<head>" +
								"<title>Department list</title>" +
						"</head>");
		out.println("<body>");
		out.println("<h1>DeptList</h1>");
		out.println("<table border='1' width='90%'>");
		out.println("<tr>" +
						"<td>ID</td>" +
						"<td>Dept_Name</td>"+
						"<td>Dept_location</td>"+
						"</tr>");
		for(Dept dept :list){
			out.println("<tr>" +
							"<td>"+dept.getId()+"</td>"+
							"<td>"+dept.getName()+"</td>"+
							"<td>"+dept.getLocation()+"</td>"+
							"</tr>");
		}
		out.println("<tr>");
		out.println("<td>favorite</td>");
		out.println("<td>");
		out.println("C++<input type='checkbox' name='favorite' value'C++' />");
		out.println("Core Java<input type='checkbox' name='favorite' value'Corejava' />");
		out.println("C# <input type='checkbox' name='favorite' value'C#' />");
		out.println("Servlet<input type='checkbox' name='favorite' value'servlet' />");
		out.println("</td>");
		out.println("<td>你可以选择多个</td>");
		out.println("</tr>");
		out.println("</table>");
		out.println("</body>");
		out.println("</html>");
		
	}

}
